<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.etc.controller.*" %>
<%@page import="com.etc.entity.*" %>
<%@page import="com.etc.dao.*" %>
<%@page import="com.etc.service1.*" %>
<%@page import="com.etc.service.impl.*" %>
<%@page import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>羔羊论坛</title>
<link rel="icon" type="image/x-icon" href="img/sheep.ico" />
<link rel="stylesheet" type="text/css" href="css/messagedetail.css" />
</head>
<body>
<%
	request.setCharacterEncoding("UTF-8");
AnsAnswerServiceDao aadao = new AnsAnswerServiceDaoImpl();
Message upmessage = (Message)request.getSession().getAttribute("message");
List<AnsMessage> list = (List<AnsMessage>)request.getSession().getAttribute("anslist");
	String username = (String)request.getSession().getAttribute("username");
	
	String ansname=(String)request.getParameter("ansname");
	int ansid = Integer.parseInt(request.getParameter("ansid"));
	
	String userrole = (String)request.getSession().getAttribute("userrole");
	//String jin_info = (String)request.getSession().getAttribute("jin_info");
	int flag=0;
	int upid=0;
	int floorid=0;
	int sum=0;
	//楼主名字
	String upname=upmessage.getUsername();
	upid=upmessage.getId();
	
	for(int i=0;i<list.size();i++)
	{
		if(list.get(i).getId()==ansid)
		{
%>
 	    <div id="up">
	 	    		<%
	 	    			if(list.get(i).getStatus()=="正常"||"正常".equals(list.get(i).getStatus()))
	 	    			{
	 	    		%>
		 			    <font class="title" style=""><%=list.get(i).getTitle() %></font>
		 	    		<p class="name"><b><%=list.get(i).getUsername() %></b>&nbsp;&nbsp;&nbsp;&nbsp;<font class="date"><%=list.get(i).getDate() %></font></p>
	 	    			<p class="cont">&nbsp;&nbsp;<%=list.get(i).getContent() %></p>
	 	    		<%
	 	    			}
	 	    		else 
	 	    			{
	 	    		%>
	 	    			<font class="title" style="color:red"><%=list.get(i).getTitle() %></font>
		 	    		<p class="name" style="color:red"><b><%=list.get(i).getUsername() %></b>&nbsp;&nbsp;&nbsp;&nbsp;<font class="date" style="color:red"><%=list.get(i).getDate() %></font></p>
	 	    			<p class="cont" style="color:red">&nbsp;&nbsp;用户发言涉嫌违规内容，已屏蔽该内容</p>
 	    		 <% 
	 	    			}
 	    			if("user"==userrole||"user".equals(userrole))
 	    			{
 	    				//楼主或者评论的人
 	    				if((list.get(i).getUsername()==username||list.get(i).getUsername().equals(username))||username==upname||username.equals(upname))
 	    				{
 	    					flag=1;
 	    		%>
 	    			<div class="caozuo">
		 	    		<form action="AnsAnswerServlet?aa=answer" method="post">
		 	    		<%
	 	    			if(list.get(i).getStatus()=="正常"||"正常".equals(list.get(i).getStatus()))
	 	    			{
	 	    			%>
 	 	    					<input type="hidden" value="<%=upid%>" name="upid">
		 	    				<input type="hidden" value="<%=list.get(i).getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=list.get(i).getId() %>" name="ansid">
		 	    				<input type="hidden" value="<%=list.get(i).getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
 	 	    					<input type="text" name="content" id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
	 	 	    				<input class="hui" type="submit" value="回复">
	 	 	    		<%
	 	    			}
	 	 	    		%>
		 	    				<span class="shan"><a href="AnsMessageServlet?am=del&title=<%=list.get(i).getTitle() %>&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;删除</a></span>
 	 	    			</form>
 					</div>
 	    		<%
 	    				}
 	 	    			else
 	 	    			{
 	 	    	%>
 	 	    			<div class="caozuo">
 	 	    				<form action="AnsAnswerServlet?aa=answer" method="post">
 	 	    				<%
		 	    			if(list.get(i).getStatus()=="正常"||"正常".equals(list.get(i).getStatus()))
		 	    			{
		 	    			%>
 	 	    					<input type="hidden" value="<%=upid%>" name="upid">
 	 	    					<input type="hidden" value="<%=list.get(i).getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=list.get(i).getId() %>" name="ansid">
		 	    				<input type="hidden" value="<%=list.get(i).getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
 	 	    					<input type="text" name="content" id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
 	 	    					<input type="submit" class="hui" value="回复">
 	 	    				<%
		 	    			}
 	 	    				%>
 	 	    				</form>
 	 					</div>
 	 	    	<%
 	 	    			}
 	    			}
 	    			else if("admin"==userrole||"admin".equals(userrole))
 	    			{		
 	    		%>
 	    			<div class="caozuo">
		 	    		<form action="AnsAnswerServlet?aa=answer" method="post">
		 	    		<%
		 	    		if(list.get(i).getStatus()=="正常"||"正常".equals(list.get(i).getStatus()))
		 	    		{
		 	    		%>
 	 	    					<input type="hidden" value="<%=upid%>" name="upid">
 	 	    					<input type="hidden" value="<%=list.get(i).getTitle() %>" name="title">
		 	    				<input type="hidden" value="<%=list.get(i).getId() %>" name="ansid">
		 	    				<input type="hidden" value="<%=list.get(i).getType() %>" name="type">
		 	    				<input type="hidden" value="<%=username %>" name="username">
 	 	    					<input type="text" name="content" id="content" style="background:transparent;line-height:30px;margin-left:20px;font-size:14px;font-family:'微软雅黑';border:1px solid black" size="100">
 	 	    					<input type="submit" class="hui" value="回复">
 	 	    			<%
		 	    		}
 	 	    			%>
		 	    				<span class="shan"><a href="AnsMessageServlet?am=del&title=<%=list.get(i).getTitle() %>&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;删除</a></span>
 						<%
 							if("正常"==list.get(i).getStatus()||"正常".equals(list.get(i).getStatus()))
 							{
 						%>
 							<span class="jie"><a href="AnsMessageServlet?am=feng&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;封禁</a></span>
 	 	    			<%
 							}
 	 	    				else if("封禁"==list.get(i).getStatus()||"封禁".equals(list.get(i).getStatus()))
 	 	    				{
 	 	    			%>
 	 	    				<span class="jie"><a href="AnsMessageServlet?am=jie&id=<%=list.get(i).getId()%>&ansid=<%=list.get(i).getAnsid()%>">&nbsp;解禁</a></span>
 	 	    			<%
 	 	    				}
 	 	    			%>
 	 	    			</form>
 					</div>
 	    		<%
 	    			}
 	    		%>
 	    </div>
<%
		}
	}
	int xuhao=0;
	List<AnsAnswer> ansanslist=aadao.findAnswerAnsMessage(ansid);
	for(int i=0;i<ansanslist.size();i++)
	{
		if((ansid==ansanslist.get(i).getAnsid()))
		{
			xuhao+=1;
			if(ansanslist.get(i).getStatus()=="正常"||ansanslist.get(i).getStatus().equals("正常"))
			{
%>
			<div class="ans">
			 	   		<p class="name">&nbsp;#<%=xuhao %>&nbsp;<b>&nbsp;<%=ansanslist.get(i).getUsername() %></b>&nbsp;&nbsp;&nbsp;<font class="date"><%=ansanslist.get(i).getDate() %></font></p>
			 	    	<font class="cont">&nbsp;&nbsp;&nbsp;<%=ansanslist.get(i).getContent() %></font>
		 	    <% 
 	    			if("user"==userrole||"user".equals(userrole))
 	    			{
 	    				if(flag==1)
 	    				{
 	    		%>
 	    			<div class="caozuo">
		 	    		<span class="shan"><a href="AnsAnswerServlet?aa=del&title=<%=ansanslist.get(i).getTitle() %>&id=<%=ansanslist.get(i).getId()%>&ansid=<%=ansanslist.get(i).getAnsid()%>">&nbsp;删除</a></span>
 					</div>
 	    		<%
 	    				}
 	    				else if(ansanslist.get(i).getUsername()==username||ansanslist.get(i).getUsername().equals(username))
 	    				{
 	    		%>
 	    			<div class="caozuo">
		 	    		<span class="shan"><a href="AnsAnswerServlet?aa=del&title=<%=ansanslist.get(i).getTitle() %>&id=<%=ansanslist.get(i).getId()%>&ansid=<%=ansanslist.get(i).getAnsid()%>">&nbsp;删除</a></span>
 					</div>
 	    		<%
 	    				}
 	    				else
 	    				{
 	    	 	    		%>
 	    	 	    			<div class="caozuo">
 	    	 					</div>
 	    	 	    		<%
 	    	 	    				}
 	    			}
 	    			else if("admin"==userrole||"admin".equals(userrole))
 	    			{		
 	    		%>
 	    			<div class="caozuo">
		 	    		<span class="shan"><a href="AnsAnswerServlet?aa=del&title=<%=ansanslist.get(i).getTitle() %>&id=<%=ansanslist.get(i).getId()%>&ansid=<%=ansanslist.get(i).getAnsid()%>">&nbsp;删除</a></span>
 						<span class="jie"><a href="AnsAnswerServlet?aa=feng&id=<%=ansanslist.get(i).getId()%>&ansid=<%=ansanslist.get(i).getAnsid()%>">&nbsp;封禁</a></span>
 					</div>
 	    		<%
 	    			}
 	    		%>
 	    		
 			</div>
 <%				
			}
			else
			{
%>
			<div class="ans">
 	    	<p class="name" style="color:red">&nbsp;#<%=xuhao %>&nbsp;<b>&nbsp;<%=ansanslist.get(i).getUsername() %></b>&nbsp;&nbsp;&nbsp;<font class="date" style="color:red"><%=ansanslist.get(i).getDate() %></font></p>
 	    	<font class="cont" style="color:red">&nbsp;&nbsp;用户发言涉嫌违规内容，已屏蔽该内容</font>
 	    		<%
 	    			if("admin"==userrole||"admin".equals(userrole))
	    			{		
	    		%>
	    			<div class="caozuo">
		 	    		<span class="shan"><a href="AnsAnswerServlet?aa=del&title=<%=ansanslist.get(i).getTitle() %>&id=<%=ansanslist.get(i).getId()%>&ansid=<%=ansanslist.get(i).getAnsid()%>">&nbsp;删除</a></span>
 						<span class="jie"><a href="AnsAnswerServlet?aa=jie&id=<%=ansanslist.get(i).getId()%>&ansid=<%=ansanslist.get(i).getAnsid()%>">&nbsp;解禁</a></span>
					</div>
	    		<%
	    			}
 	    			else if(flag==1)
 	    			{
 	    				%>
 	    			<div class="caozuo">
		 	    		<span class="shan"><a href="AnsAnswerServlet?aa=del&title=<%=ansanslist.get(i).getTitle() %>&id=<%=ansanslist.get(i).getId()%>&ansid=<%=ansanslist.get(i).getAnsid()%>">&nbsp;删除</a></span>
 					</div>
 	    		<%
					}
	    		%> 
 			</div>
<%			
			}
		}
	}
%>
</body>
</html>